<template>
	<view class="seeImage">
		<view class="title">左右滑动查看，{{current+1}}/{{list.length}}</view>
		<uni-icons class="close" @tap="close" type="closeempty" size="18" color="#fff"></uni-icons>
		<view class="imgArr">
			<swiper :current="current" @change="changea">
				<swiper-item v-for="item in list" :key="item">
					<image :src="item"></image>
				</swiper-item>
			</swiper>
		</view>
		<view class="bao" @tap="downloadFile">保存图片</view>
	</view>
</template>

<script lang="ts" setup>
import {ref,computed} from 'vue'

const props = defineProps(['list','imgIndex'])
const current = ref<number>(0)
const changea = (e) =>{
	current.value = e.detail.current
}
const emit = defineEmits(['close'])
const close = ()=>{
	emit('close')
}
const downloadFile = ()=>{
	uni.downloadFile({
		url: props.list[current.value],
		success: (res) => {
			console.log(res)
			if (res.statusCode === 200) {
				 uni.saveImageToPhotosAlbum({
				    filePath: res.tempFilePath,
				    success: () => {
				        uni.showToast({ title: "图片保存成功", icon: "success" });
				    },
				    fail: () => {
				        uni.showToast({ title: "图片保存失败", icon: "error" });
				    }
				});
				
			}
		}
	});

}
</script>

<style lang="scss" scoped>
.seeImage{
	width: 100vw;
	height: 100vh;
	z-index: 999;
	position: relative;
	background-color: #000;
	position: fixed;
	left: 0;top: 0;
	.title{
		font-size: 28rpx;
		color: #FFFFFF;
		font-weight: bold;
		text-align: center;
		margin: 96rpx 0 96rpx;
	}
	.close{
		position: absolute;
		top: 92rpx;
		right: 48rpx;
	}
	.imgArr{
		
	}
	swiper{
		width: 100%;
		height: 894rpx;
		image{
			width: 100%;
			height: 894rpx;
		}
	}
	.bao{
		width: 200rpx;
		height: 80rpx;
		background: rgba(0,0,0,0.35);
		border-radius: 200rpx;
		border: 2rpx solid #FFFFFF;
		margin: 66rpx auto 0;
		box-sizing: border-box;
		font-size: 30rpx;
		color: #FFFFFF;
		@include flex(center,center);
	}
}
</style>
